#include "message.hpp"
#include "net.hpp"
#include <c++/11/bits/this_thread_sleep.h>
#include<iostream>

void onMessage(const yfrpc::BaseConnection::ptr& conn, yfrpc::BaseMessage::ptr& msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
}


int main()
{
    auto client = yfrpc::ClientFactory::create("127.0.0.1", 9090);
    client->setMessageCallback(onMessage);
    client->connect();

    auto rpc_req = yfrpc::MessageFactory::create<yfrpc::RpcRequest>();
    rpc_req->setId("11111");
    rpc_req->setMType(yfrpc::MType::REQ_RPC);
    rpc_req->setMethod("Add");
    Json::Value param;
    param["num1"] = 11;
    param["num2"] = 22;
    rpc_req->setParams(param);
    client->send(rpc_req);
    std::this_thread::sleep_for(std::chrono::seconds(10));
    client->shutdown();
    return 0;
}